#coding:utf-8
import pandas as pd

book = pd.read_csv('./src/book_data.csv',encoding='gbk')
author_ls = list(book['作者'][:4])
# 重置索引更改列名
df = pd.DataFrame(book)
# df = df.reset_index().rename(columns={'index': '作者', '作者': "轻松", '作者': "正剧",'作者': "爆笑",'作者':"悲剧"})
df = pd.DataFrame(index=author_ls,columns=["轻松","正剧","爆笑","悲剧"])
df.fillna(0,inplace=True)
# author_book = book.groupby(by='作者').value_counts()
for i in author_ls:
    # print('\n',i)
    # print(author_book[i])
    style_ls = list(book.loc[book['作者']==i]['作品风格'])
    for j in style_ls:
        df[j][i]+=1

df.to_excel('./src2/book_style_head4.xlsx')
print(df)

